<extend name="Public/base"/>
<block name="body">
    <div class="main-title">
        <h2>
            新增友链
        </h2>
    </div>
    <form action="{:U('add')}" class="form-horizontal" method="post" enctype="multipart/form-data">
        <div class="form-item">
            <label class="item-label">
                友链标题
                <span class="check-tips">
                </span>
            </label>
            <div class="controls">
                <input class="text input-large" name="title" type="text" value="">
                </input>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">
                友链地址
                <span class="check-tips">
                </span>
            </label>
            <div class="controls">
                <input class="text input-large" name="url" type="text" value="">
                </input>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">
                友链描述
                <span class="check-tips">
                </span>
            </label>
            <div class="controls">
                <input class="text input-large" name="des" type="text" value="">
                </input>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">
                友链图片
                <span class="check-tips">
                </span>
            </label>
            <div class="controls">
                <input class="text input-large" name="pic" type="file" value="">
                </input>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">
                状态
                <span class="check-tips">
                </span>
            </label>
            <div class="controls">
                <label class="radio">
                    <input class="" name="status" type="radio" value="0">
                    隐藏
                    </input>
                </label>
                <label class="radio">
                    <input checked="" class="" name="status" type="radio" value="1">
                    显示
                    </input>
                </label>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">
                创建时间
                <span class="check-tips">
                </span>
            </label>
            <input class="text input-large time" name="ctime" placeholder="请选择时间" type="text" value=""/>
        </div>
        <div class="form-item">
            <label class="item-label">
                到期时间
                <span class="check-tips">
                </span>
            </label>
            <input class="text input-large time" name="endtime" placeholder="请选择时间" type="text" value=""/>
        </div>
        <div class="form-item">
            <button class="btn submit-btn " id="submit" target-form="form-horizontal" type="submit">
                确 定
            </button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">
                返 回
            </button>
        </div>
    </form>
</block>
<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('
        User / index
        ')}'
        )
        ;
    </script>
</block>
<block name="script">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">

$('#submit').click(function(){
    $('#form').submit();
});

$(function(){
    $('.time').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        language:"zh-CN",
        minView:2,
        autoclose:true
    });
    showTab();

    <if condition="C('OPEN_DRAFTBOX') and (ACTION_NAME eq 'add' or $info['status'] eq 3)">
    //保存草稿
    var interval;
    $('#autoSave').click(function(){
        var target_form = $(this).attr('target-form');
        var target = $(this).attr('url')
        var form = $('.'+target_form);
        var query = form.serialize();
        var that = this;

        $(that).addClass('disabled').attr('autocomplete','off').prop('disabled',true);
        $.post(target,query).success(function(data){
            if (data.status==1) {
                updateAlert(data.info ,'alert-success');
                $('input[name=id]').val(data.data.id);
            }else{
                updateAlert(data.info);
            }
            setTimeout(function(){
                $('#top-alert').find('button').click();
                $(that).removeClass('disabled').prop('disabled',false);
            },1500);
        })

        //重新开始定时器
        clearInterval(interval);
        autoSaveDraft();
        return false;
    });

    //Ctrl+S保存草稿
    $('body').keydown(function(e){
        if(e.ctrlKey && e.which == 83){
            $('#autoSave').click();
            return false;
        }
    });

    //每隔一段时间保存草稿
    function autoSaveDraft(){
        interval = setInterval(function(){
            //只有基础信息填写了，才会触发
            var title = $('input[name=title]').val();
            var name = $('input[name=name]').val();
            var des = $('textarea[name=description]').val();
            if(title != '' || name != '' || des != ''){
                $('#autoSave').click();
            }
        }, 1000*parseInt({:C('DRAFT_AOTOSAVE_INTERVAL')}));
    }
    autoSaveDraft();

    </if>

});
</script>
</block>


